package com.ekuaitu.kuaitu.activity;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;

import com.ekuaitu.kuaitu.R;
import com.ekuaitu.kuaitu.api.ApiStore;
import com.ekuaitu.kuaitu.api.UrlConstant;
import com.ekuaitu.kuaitu.base.BaseActivity;
import com.ekuaitu.kuaitu.bean.MyInvoiceBean;
import com.ekuaitu.kuaitu.utils.AppManager;
import com.ekuaitu.kuaitu.utils.MyApplication;
import com.ekuaitu.kuaitu.utils.SharedPreferencesUtils;
import com.ekuaitu.kuaitu.utils.Toast.ToastCompat;
import com.handmark.pulltorefresh.library.PullToRefreshListView;
import com.ekuaitu.kuaitu.utils.StatusBarUtil;
import com.zhy.autolayout.AutoRelativeLayout;

import butterknife.BindView;
import butterknife.OnClick;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class MyInvoiceActivity extends BaseActivity {

    @BindView(R.id.return_myInvoice)
    ImageView returnMyInvoice;
    @BindView(R.id.toolbar_myInvoice)
    AutoRelativeLayout toolbarMyInvoice;
    @BindView(R.id.invoice_tv_all)
    TextView invoiceTvAll;
    @BindView(R.id.invoice_tv_guide)
    TextView invoiceTvGuide;
    @BindView(R.id.invoice_tv_history)
    TextView invoiceTvHistory;
    @BindView(R.id.invoice_ll_all)
    AutoRelativeLayout invoiceLlAll;
    @BindView(R.id.invoice_lv)
    PullToRefreshListView invoiceLv;
    @BindView(R.id.invoice_tv_allMoney)
    TextView invoiceTvAllMoney;
    @BindView(R.id.invoice_tv_totalRoute)
    TextView invoiceTvTotalRoute;
    @BindView(R.id.invoice_tv_next)
    TextView invoiceTvNext;
    @BindView(R.id.activity_my_invoice)
    AutoRelativeLayout activityMyInvoice;
    @BindView(R.id.invoice_pBar)
    ProgressBar invoicePBar;

    private Context mContext = this;
    private int PAGE = 1;

    @Override
    public int getLayoutId() {
        return R.layout.activity_my_invoice;
    }

    @Override
    public void initView() {
        StatusBarUtil.setColor(this, getResources().getColor(R.color.colorPrimaryWhite), 0,true);
        getInvoice();
    }

    private void getInvoice() {
        invoicePBar.setVisibility(View.VISIBLE);
        ApiStore.getInstance().getApiService(UrlConstant.Request.BASE_URL).getInvoiceList( MyApplication.getInstance().getRequestFieldMap(),PAGE + "", "6").enqueue(new Callback<MyInvoiceBean>() {
            @Override
            public void onResponse(Call<MyInvoiceBean> call, Response<MyInvoiceBean> response) {
                if (response.isSuccessful() && response.body() != null) {
                    if (response.body().getStatus() == 200) {
                        invoicePBar.setVisibility(View.GONE);
                    } else {
                        ToastCompat.makeText(mContext, response.body().getMessage(), Toast.LENGTH_SHORT).show();
                    }
                }
            }

            @Override
            public void onFailure(Call<MyInvoiceBean> call, Throwable t) {
                invoicePBar.setVisibility(View.GONE);
                ToastCompat.makeText(mContext, getResources().getString(R.string.badNetwork), Toast.LENGTH_SHORT).show();
            }
        });
    }


    @OnClick({R.id.return_myInvoice, R.id.invoice_tv_all, R.id.invoice_tv_guide, R.id.invoice_tv_history, R.id.invoice_tv_next})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.return_myInvoice:
                finish();
                break;
            case R.id.invoice_tv_all:
                break;
            case R.id.invoice_tv_guide:
                break;
            case R.id.invoice_tv_history:
                startActivity(new Intent(MyInvoiceActivity.this, MyInvoiceHistoryActivity.class));
                break;
            case R.id.invoice_tv_next:
                startActivity(new Intent(MyInvoiceActivity.this, InvoiceSettlementActivity.class));
                break;
        }
    }

}
